package com.sqfw.project.wp.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sqfw.common.utils.PhoneNumberMasking;
import com.sqfw.common.utils.poi.ExcelUtil;
import com.sqfw.framework.aspectj.lang.annotation.Log;
import com.sqfw.framework.aspectj.lang.enums.BusinessType;
import com.sqfw.framework.web.controller.BaseController;
import com.sqfw.framework.web.domain.AjaxResult;
import com.sqfw.framework.web.page.TableDataInfo;
import com.sqfw.project.wp.domain.TSmsUser;
import com.sqfw.project.wp.service.TSmsUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "通讯录")
@RestController
@RequestMapping("/sms_user/sms_user")
public class TSmsUserController extends BaseController {

    @Autowired
    private TSmsUserService tSmsUserService;

    /**
     * 查询通讯录列表
     */
    @ApiOperation("查询通讯录列表")
    @PreAuthorize("@ss.hasPermi('sms_user:sms_user:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSmsUser tSmsUser)
    {
        LambdaQueryWrapper<TSmsUser> listWrapper = tSmsUserService.getListWrapper(tSmsUser);
        startPage();
        List<TSmsUser> list = tSmsUserService.list(listWrapper);
        // 对号码进行脱敏处理
       /* for(TSmsUser tSmsUser1 : list){
            tSmsUser1.setMobile(PhoneNumberMasking.maskPhoneNumber(tSmsUser1.getMobile()));
        }*/
        return getDataTable(list);
    }

    /**
     * 导出通讯录
     */
    @Log(title = "通讯录", businessType = BusinessType.EXPORT)
    @ApiOperation("导出通讯录")
    @PreAuthorize("@ss.hasPermi('sms_user:sms_user:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSmsUser tSmsUser)
    {
        LambdaQueryWrapper<TSmsUser> listWrapper = tSmsUserService.getListWrapper(tSmsUser);
        List<TSmsUser> list = tSmsUserService.list(listWrapper);
        ExcelUtil<TSmsUser> util = new ExcelUtil<TSmsUser>(TSmsUser.class);
        util.exportExcel(response, list, "通讯录表数据");
    }

    /**
     * 获取通讯录详细信息
     */
    @ApiOperation("获取通讯录详细信息")
    @PreAuthorize("@ss.hasPermi('sms_user:sms_user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        TSmsUser tSmsUser = tSmsUserService.getById(id);
        // tSmsUser.setMobile(PhoneNumberMasking.maskPhoneNumber(tSmsUser.getMobile())); // 号码脱敏
        return success(tSmsUser);
    }

    /**
     * 新增通讯录
     */
    @ApiOperation("新增通讯录")
    @Log(title = "通讯录", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('sms_user:sms_user:add')")
    @PostMapping
    public AjaxResult add(@RequestBody TSmsUser tSmsUser)
    {
        return toAjax(tSmsUserService.saveSmsUser(tSmsUser));
    }

    /**
     * 修改通讯录
     */
    @ApiOperation("修改通讯录")
    @Log(title = "通讯录", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('sms_user:sms_user:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody TSmsUser tSmsUser)
    {
        return toAjax(tSmsUserService.saveSmsUser(tSmsUser));
    }

    /**
     * 删除通讯录
     */
    @ApiOperation("删除通讯录")
    @Log(title = "通讯录", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('sms_user:sms_user:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tSmsUserService.removeSmsUsers(ids));
    }
}
